<!--
 * @Author: CNN 969682281@qq.com
 * @Date: 2023-03-07 13:36:39
 * @LastEditors: CNN 969682281@qq.com
 * @LastEditTime: 2024-01-19 16:31:48
 * @FilePath: \newMould_BHZ\src\views\WaterManage\trends\instantly.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <!-- 水稳----动态监控---实时监控 -->
  <div class="department" id="department">
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav app-container-search">
        <!-- 左侧 -->
        <el-form ref="form" :model="getList" label-width="110px">
          <el-row :gutter="20">
            <el-col :span="6"
              ><el-form-item label="项目名称：">
                <el-select
                  class="selectBhz"
                  v-model="getList.fprojectid"
                  placeholder="所有项目"
                  @change="selectProject"
                >
                  <el-option
                    v-for="v in projectsObj"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="标段名称：">
                <el-select
                  class="selectBhz"
                  v-model="getList.fCompanyid"
                  placeholder="所有标段"
                  @change="selectTender"
                >
                  <el-option
                    v-for="v in tendersObj"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="年份：">
                <el-date-picker
                  class="selectBhz"
                  @change="selectTime"
                  v-model="getList.timeStr"
                  type="year"
                  placeholder="选择年"
                  format="yyyy 年"
                  value-format="yyyy"
                >
                </el-date-picker> </el-form-item
            ></el-col>
            <el-col :span="6">
              <el-form-item label="梁场名称：">
                <el-select
                  class="selectBhz"
                  v-model="getList.stationId"
                  placeholder="梁场查询"
                  @change="selectStation"
                >
                  <el-option
                    v-for="v in bhzDataList"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="6">
              <el-form-item label="压浆机名称：">
                <el-select
                  class="selectBhz"
                  v-model="getList.machineId"
                  placeholder="压浆机查询"
                >
                  <el-option
                    v-for="v in bhjDataList"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col
              :span="6"
              :offset="12"
              class="searchBtn"
              style="text-align: right; display: flex; justify-content: end"
            >
              <el-form-item>
                <el-button
                  type="primary"
                  :loading="editLoading"
                  @click="yj_searchForm(getList)"
                  >查询</el-button
                >
                <el-button @click="reset">重置</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <!-- 内容 -->
      <div class="text_table TensionExceedHandle">
        <div class="materialTable" style="height: 300px">
          <tableData
            :stripe="false"
            :issss="false"
            v-if="table_config.thead.length > 1"
            :config="table_config"
            :dataList="tableData"
            :loading="listLoading"
            @selection-change="selectionChange"
            @sort-change="sortChange"
          />
        </div>

        <div class="materialCharts">
          <myCharts
            :time1="this.value2[0]"
            :time2="this.value2[1]"
            :commonData="chartsData"
          >
          </myCharts>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import actions from "@/actions";
import TableData from "@/components/public/el-table"; //主页面列表
import myCharts from "@/components/TensionAndGrout/TensionManage/GroutManage/GroutExceedHandlecharts";

// import formJs from "./regexDetail.js"; //新增弹框配置项
import {
  getGroutingTrend, //主页面列表接口
  getStationmachineList, //梁场设备查询
  getMachineListByStationId, //4压浆机、5压浆机设备查询
} from "@/api/request.js";
// import { statusTypes } from "@/utils/config"; //配置项
export default {
  name: "GroutExceedHandle",
  components: {
    TableData, //主页面列表
    myCharts,
  },
  data() {
    return {
      name: "GroutExceedHandle", //按钮配置页面代号
      editLoading: false,

      // 顶部下拉框
      bhzDataList: [], //梁场
      bhjDataList: [], //压浆机
      projectsObj: [], //项目名
      tendersObj: [],
      value2: "", //主页面日期筛选绑定值

      // 顶部下拉框

      // 列表
      table_config: {
        imgKeyWord: "url",
        fileKeyWord: "url",
        fileName: "fFileName",
        dialogHeight: "",
        thead: [],
        isCheckBox: false,
        isIndex: false,
        isOperation: true,
        // 表格操作列
      },

      tableData: [], //列表数据列表
      listLoading: false, //列表数据加载loading
      getList: {
        fprojectid: "",
        fCompanyid: "", // 施工标段id，不为空
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        stationId: "", // 梁场id
        machineId: "", // 压浆机id
        warningLevel: "", // 预警等级
        fCloseoperation: "", // 闭合状态
        keyWord: "", //  模糊条件
        page: 1, // 当前页数
        pageSize: 15, // 每页显示条数
        timeStr: "", // 查询的年份
        fProjectposition: "", //工程部位模糊查询
        taskNo: "", //任务单模糊查询
        fStatus: "", //状态
        keyType: "2", ////张拉 1 压浆 2 必填
      },
      //echarts
      chartsData: {}, //echarts数据
      //echarts

      rowInfo: null, //当前行信息
      userInfo: {}, //登录用户
      token: null,
    };
  },

  mounted() {
    actions.onGlobalStateChange((state, prev) => {
      this.userInfo = prev.currentUser;
      this.token = prev.token;
      var data = prev.currentUser.projects;
      this.projectsObj = [
        {
          fItemName: "所有项目",
          fItemValue: "",
        },
      ];
      data.map((item) => {
        this.projectsObj.push({
          fItemName: item.projectName,
          fItemValue: item.projectId,
        });
      });
    }, true);
    this.getDate();
  },
  methods: {
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(
        sessionStorage.getItem("GxEmbedded_instantly")
      );
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        // this.yj_view = btnStr.includes("yj_view");
      } else {
        // this.yj_view = true;
      }
    },
    selectProject(e) {
      this.tendersObj = [];
      this.bhzDataList = [];
      this.getList.fCompanyid = "";
      this.getList.stationId = "";
      this.getList.machineId = "";
      this.bhjDataList = [];
      this.getTender(e,1);
    },
    async getTender(e,num) {
      await this.$http(
        " http://172.18.5.31:8300/IOTManagement/Base/Company/getGXJLBaseCompanyList.do?projectId=" +
          e,
        {
          headers: {
            "Content-Type": "application/json",
            Authorization: localStorage.getItem("access_token"),
          },
        }
      ).then((res) => {
        if (res.status == 200) {
          var data = res.data.data.GXCompanyList;
          this.tendersObj = [];
          if (data.length == 1) {
            data.map((item) => {
              this.tendersObj.push({
                fItemName: item.sectionName,
                fItemValue: item.sectionId,
              });
            });
            this.getList.fCompanyid = data[0].sectionId;
          } else {
            this.tendersObj = [
              {
                fItemName: "所有标段",
                fItemValue: "",
              },
            ];
            data.map((item) => {
              this.tendersObj.push({
                fItemName: item.sectionName,
                fItemValue: item.sectionId,
              });
            });
          }

            if (num == 0) {
            // num==0 调列表；num==1 不调
            this.yj_searchForm(this.getList);
          }
        }
      });
    },
    selectTender(e) {
      this.getList.stationId = "";

      this.getList.machineId = "";
      this.bhjDataList = [];
      this.bhzDataList = [];

      this.mixingPlantList(0, this.getList);
    },
    selectStation(e) {
      this.getList.machineId = "";
      this.getList.stationId = e;
      this.bhjDataList = [];
      this.getbhjDataMethods(e, 4);
    },
    // 重置按钮
    reset() {
      this.timeDuring = "";
      this.getList = {
        fCompanyid: "", // 施工标段id，不为空
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        stationId: "", // 梁场id
        machineId: "", // 压浆机id
        warningLevel: "", // 预警等级
        fCloseoperation: "", // 闭合状态
        keyWord: "", //  模糊条件
        page: 1, // 当前页数
        pageSize: 15, // 每页显示条数
        timeStr: "",
        fProjectposition: "", //工程部位模糊查询
        taskNo: "", //任务单模糊查询
        fStatus: "", //状态
        keyType: "2", ////张拉 1 压浆 2 必填
      };
    },
    // 获取列表数据
    yj_searchForm(data) {
      this.listLoading = true;
      this.chartsData = {
        months: [],
        ActualCalculation: [],
        DiskNumber: [],
        rate: [],
        unQuantity: [],
        unrate: [],
      };
      this.tableData = [];
      this.table_config.thead = [
        {
          label: "月份",
          prop: "type",
          minWidth: "100px",
          align: "center",
        },
      ];
      if (data.machineId == "所有压浆机") {
        data.machineId = "";
      }
      if (data.stationId == "所有梁场") {
        data.stationId = "";
      }
      window.sessionStorage.setItem(
        "GxEmbedded_GroutManage_getLists",
        JSON.stringify(data)
      );
      var id;
      if (data.fCompanyid != "") {
        id = data.fCompanyid;
      } else {
        id = data.fprojectid;
      }
      var sc = {
        companyId: id, // 施工标段id
        timeStr: data.timeStr, // 查询的年份
        machineId: data.machineId, // 拌和机编号
        stationId: data.stationId, // 梁场编号
      };

      getGroutingTrend(sc)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.listLoading = false;
            var months = []; //月份
            var assemble = []; //压浆总数
            var quantity = []; //合格数
            var rate = []; //合格率
            var unQuantity = []; //不合格数
            var unrate = []; //不合格率

            var tableData = [{}, {}, {}, {}, {}];
            var data = res.data;
            months = data.dateList; //月份
            assemble = data.totalCountList; //压浆总数
            quantity = data.qualifiedCountList; //合格数
            rate = data.qualifiedRateList; //合格率
            unQuantity = data.unQualifiedCountList; //不合格数
            unrate = data.unQualifiedRateList; //不合格率

            // 图表数据
            this.chartsData = {
              //月份---X轴
              months: months,
              //压浆总数
              ActualCalculation: assemble,
              //合格数
              DiskNumber: quantity,
              //合格率
              rate: rate,
              //不合格数
              unQuantity: unQuantity,
              //不合格率
              unrate: unrate,
            };

            months.map((item, index) => {
              this.table_config.thead.push({
                label: item,
                prop: item,
                minWidth: "100px",
                align: "center",
              });
              tableData[0].type = "压浆总数";
              tableData[0][item] = assemble[index];
              tableData[1].type = "合格数";
              tableData[1][item] = quantity[index];
              tableData[2].type = "合格率(%)";
              tableData[2][item] = rate[index];
              tableData[3].type = "不合格数";
              tableData[3][item] = unQuantity[index];
              tableData[4].type = "不合格率(%)";
              tableData[4][item] = unrate[index];
            });

            that.tableData = tableData;
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

    // 获取梁场数据
    mixingPlantList(num, datas) {
      this.bhzDataList = [
        {
          fItemName: "所有梁场",
          fItemValue: "",
        },
      ];
      var data = {
        companyId: datas.fCompanyid, // 施工标段id
        modelType: num, // 类型
        stationType: "4", // 拌合站类型
      };
      getStationmachineList(data)
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            arr.map((item) => {
              this.bhzDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

    // 获取压浆机设备
    getbhjDataMethods(data, num) {
      getMachineListByStationId({ stationId: data, modelType: num })
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;
            
            this.bhjDataList = [
              {
                fItemName: "所有压浆机",
                fItemValue: "",
              },
            ];
            arr.map((item) => {
              this.bhjDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 时间间隔
    selectTime(e) {
      this.getList.timeStr = e;
      this.value2 = [e + "年1月", e + "年12月"];
    },

    getDate() {
      let year = new Date().toString().match(/(\d{4})/)[0];
      this.value2 = [year + "年1月", year + "年12月"];
      if (
        JSON.parse(sessionStorage.getItem("GxEmbedded_GroutManage_getLists"))
      ) {
        var getList = JSON.parse(
          sessionStorage.getItem("GxEmbedded_GroutManage_getLists")
        );

        if (getList.fCompanyid != "" && getList.fCompanyid != null) {
          this.mixingPlantList(0, dataList);
        }

        if (getList.stationId != "" && getList.stationId != null) {
          this.getbhjDataMethods(dataList.stationId, 4);
        }

        if (getList.fprojectid != "") {
          this.getTender(getList.fprojectid,0);
        } else {
          getList.fprojectid = this.projectsObj[1].fItemValue;
          this.getTender(getList.fprojectid,0);
        }

        if (getList.timeStr == "") {
          this.getList = {
            fprojectid: getList.fprojectid,
            fCompanyid: getList.fCompanyid, // 施工标段id，不为空
            startDates: getList.startDates, // 开始时间
            endDates: getList.endDates, // 截至时间
            stationId: getList.stationId, // 梁场id
            machineId: getList.machineId, // 张拉机id
            warningLevel: getList.warningLevel, // 预警等级
            fCloseoperation: getList.fCloseoperation, // 闭合状态
            keyWord: "", //  模糊条件
            page: 1, // 当前页数
            pageSize: 15, // 每页显示条数
            timeStr: year,
            fProjectposition: getList.fProjectposition, //工程部位模糊查询
            taskNo: getList.taskNo, //任务单模糊查询
            fStatus: getList.fStatus, //状态
            keyType: "2", ////张拉 1 压浆 2 必填
          };
        } else {
          this.getList = {
            fprojectid: getList.fprojectid,
            fCompanyid: getList.fCompanyid, // 施工标段id，不为空
            startDates: getList.startDates, // 开始时间
            endDates: getList.endDates, // 截至时间
            stationId: getList.stationId, // 梁场id
            machineId: getList.machineId, // 张拉机id
            warningLevel: getList.warningLevel, // 预警等级
            fCloseoperation: getList.fCloseoperation, // 闭合状态
            keyWord: "", //  模糊条件
            page: 1, // 当前页数
            pageSize: 15, // 每页显示条数
            timeStr: getList.timeStr,
            fProjectposition: getList.fProjectposition, //工程部位模糊查询
            taskNo: getList.taskNo, //任务单模糊查询
            fStatus: getList.fStatus, //状态
            keyType: "2", ////张拉 1 压浆 2 必填
          };
        }
      } else {
        this.getList.fprojectid = this.projectsObj[1].fItemValue;
        this.getTender(this.getList.fprojectid,0);
        this.getList.timeStr = year;
      }
      
    },
    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>


<style scoped lang='less'>
.TensionExceedHandle {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.materialCharts {
  // height: calc(100% - 200px);
  height: calc(100% - 300px) !important;
  // flex: 1;
  width: 100%;
}

.mechanism_nav_left .el-date-editor {
  width: 165px !important;
  min-width: 165px !important;
}
</style>


